package com.chenchao.net;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/25 21:24
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.net.Test10A.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 广播接收端
 */
public class Test10A {
    public static void main(String[] args) throws IOException {
        /*建码头*/
        DatagramSocket socket = new DatagramSocket(10000);
        /*建集装箱*/
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes,bytes.length);
        /*卸货*/
        socket.receive(datagramPacket);
        System.out.println(new String(datagramPacket.getData(),0, datagramPacket.getLength()));

        /*关码头*/
        socket.close();
    }
}
